home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 22 / 4 / DISK2247.ZIP / CBASE101.ZIP / BTREE101.ZIP / BTGETCUR.C < prev    next >
Text File  |  1990-06-20  |  2KB  |  74 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btgetcur.c    1.4 - 90/06/20" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8. /*#include <string.h>*/
  9.  
  10. /* local headers */
  11. #include "btree_.h"
  12.  
  13. /*man---------------------------------------------------------------------------
  14. NAME
  15.      btgetcur - get btree cursor
  16.  
  17. SYNOPSIS
  18.      #include <btree.h>
  19.  
  20.      int btgetcur(btp, btposp)
  21.      btree_t *btp;
  22.      btpos_t *btposp;
  23.  
  24. DESCRIPTION
  25.      The btgetcur function gets the current cursor position for btree
  26.      btp and copies it to btposp.  A btree position saved with
  27.      btgetcur can be used to reposition to a key using btsetcur.  It
  28.      is important to remember that a btree position is not valid after
  29.      an insertion, deletion, or unlock.
  30.  
  31.      btgetcur will fail if one or more of the following is true:
  32.  
  33.      [EINVAL]       btp is not a valid btree pointer.
  34.      [EINVAL]       btposp is the NULL pointer.
  35.      [BTELOCK]      btp is not locked.
  36.      [BTENOPEN]     btp is not open.
  37.  
  38. SEE ALSO
  39.      btsetcur.
  40.  
  41. DIAGNOSTICS
  42.      Upon successful completion, a value of 0 is returned.  Otherwise,
  43.      a value of -1 is returned, and errno set to indicate the error.
  44.  
  45. ------------------------------------------------------------------------------*/
  46. int btgetcur(btp, btposp)
  47. btree_t *btp;
  48. btpos_t *btposp;
  49. {
  50.     /* validate arguments */
  51.     if (!bt_valid(btp) || btposp == NULL) {
  52.         errno = EINVAL;
  53.         return -1;
  54.     }
  55.  
  56.     /* check if not open */
  57.     if (!(btp->flags & BTOPEN)) {
  58.         errno = BTENOPEN;
  59.         return -1;
  60.     }
  61.  
  62.     /* check locks */
  63.     if (!(btp->flags & BTLOCKS)) {
  64.         errno = BTELOCK;
  65.         return -1;
  66.     }
  67.  
  68.     /* get current position */
  69.     memcpy(btposp, &btp->cbtpos, sizeof(*btposp));
  70.  
  71.     errno = 0;
  72.     return 0;
  73. }
  74.